package com.mk.admin.controller;

import com.mk.admin.log.WriteLog;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.query.NoticeQuery;
import com.mk.admin.model.vo.NoticeVo;
import com.mk.admin.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/a/adm/notice")
@Api(tags = "通知公告")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @PostMapping("/select")
    public ResultDto select(@RequestBody NoticeQuery query) {
        return noticeService.select(query);
    }

    @PostMapping("/add")
    public ResultDto add(@RequestBody NoticeVo vo) {
        return noticeService.add(vo);
    }

    @PostMapping("/update")
    public ResultDto update(@RequestBody NoticeVo vo) {
        return noticeService.update(vo);
    }

    @PostMapping("/delete")
    public ResultDto delete(@RequestBody NoticeVo vo) {
        return noticeService.delete(vo.getId());
    }

    @WriteLog("批量删除")
    @PostMapping("/deleteBatchIds")
    @ApiOperation(value = "批量删除",notes = "只需要将每条数据放入数组即可，只要数据包含id")
    public ResultDto deleteBatchIds(@RequestBody List<NoticeVo> list) {
        return noticeService.deleteBatchIds(list);
    }

    @PostMapping("/status")
    public ResultDto status(@RequestBody NoticeVo vo) {
        return noticeService.status(vo.getId());
    }


    @PostMapping("/id")
    @ApiOperation(value = "根据id查询当前数据")
    public ResultDto selectById(@RequestBody NoticeVo vo) {
        return noticeService.selectById(vo.getId());
    }

    @PostMapping("/times")
    @ApiOperation(value = "增加浏览次数",notes = "如果当前用户已经浏览，则不增加")
    public ResultDto times(@RequestBody NoticeVo vo) {
        return noticeService.times(vo);
    }

    @PostMapping("/likes")
    @WriteLog("点赞")
    @ApiOperation("增加或者取消点赞")
    public ResultDto likes(@RequestBody NoticeVo vo) {
        return noticeService.likes(vo);
    }

    @PostMapping("/collects")
    @WriteLog("收藏")
    @ApiOperation("增加或者取消收藏")
    public ResultDto collects(@RequestBody NoticeVo vo) {
        return noticeService.collects(vo);
    }

    @PostMapping("/forwards")
    @WriteLog("转发")
    @ApiOperation("增加转发次数")
    public ResultDto forwards(@RequestBody NoticeVo vo) {
        return noticeService.forwards(vo);
    }
}
